package com.xiao.springaopdemo1.xml;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component //注解
public class loggAspects {

    public void method(JoinPoint joinPoint){
        //获取连接点所对应方法的签名信息
        Signature signature = joinPoint.getSignature();
        //获取连接点所对应方法的方法名
        String name = signature.getName();
        //获取连接点所对应的方法名的参数
        Object[] args = joinPoint.getArgs();
        System.out.println("hello word!"+"目标方法前");
        System.out.println("方法名："+name+",参数："+ Arrays.toString(args));
    }

    public void after(){
        System.out.println("目标方法后");
    }

    public void afterThrow(JoinPoint joinPoint,Throwable result){
        String message = result.getMessage();
        System.out.println(message.toString());
        System.out.println("异常方法");
    }

    public  void  afterReturn(){
        System.out.println("返回方法");
    }

    public Object around(ProceedingJoinPoint joinPoint){
        Object result=null;
        try {
            System.out.println("前置通知");
            result= joinPoint.proceed();
            System.out.println("返回通知");
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }finally {
            System.out.println("后置通知");
        }
        return result ;

    }
}
